package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.ManagerQuery;
import com.xingkeduo.pojo.table.ManagerTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class ManagerService {
    private static final String NAMESPACE = ManagerTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<ManagerTable, ManagerQuery> dao;

    //查询一条
    public ManagerTable selectById(long id) throws Throwable {
        ManagerTable managerTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(managerTable))
            return managerTable;
        return null;
    }

    //查询一条
    public ManagerTable selectByCode(long code) throws Throwable {
        ManagerTable managerTable = dao.select(NAMESPACE, code);
        if (!CommonUtil.isEmpty(managerTable))
            return managerTable;
        return null;
    }

    //查询多条
    public List<ManagerTable> selectLists(ManagerQuery managerQuery) throws Throwable {
        List<ManagerTable> managerTableList = dao.select(NAMESPACE, managerQuery);
        if (!CommonUtil.isEmpty(managerTableList))
            return managerTableList;
        return null;
    }
    //分页查询
    public Page<ManagerTable> selectPageLists(ManagerQuery managerQuery, Integer pageNo, Integer pageSize) throws Throwable {
        Page<ManagerTable> managerTablePage = dao.pageSelect(NAMESPACE,managerQuery,pageNo,pageSize);
        return managerTablePage;
    }

    //插入
    public int insert(ManagerTable managerTable) throws Throwable {
        managerTable.setCode(IdentityUtil.nextId(IdentityUtil.Worker.USER));
        return dao.insert(NAMESPACE, managerTable);
    }

    //更新
    public int update(ManagerTable managerTable) throws Throwable {
        return dao.update(NAMESPACE, managerTable);
    }

    //删除
    public int delete(ManagerTable managerTable) throws Throwable {
        return dao.update(NAMESPACE, managerTable);
    }

    //数量
    public int count(ManagerQuery managerQuery) throws Throwable {
        return dao.selectCount(NAMESPACE, managerQuery);
    }


}
